/*
 * @Date: 2020-04-08 17:16:23
 * @LastEditors: 墨墨
 * @LastEditTime: 2020-04-08 18:32:50
 * @Description:
 */
'use strict';

const Service = require('egg').Service;
class ToolService extends Service {
  async dingtalkRobot(content, type = 'text') {
    if (this.config.env === 'local') {
      return;
    }
    // app.dingtalkRobot.sendText(text, opts) - send text
    // app.dingtalkRobot.sendTextAt(text, atMobiles, opts) - send text at mobiles
    // app.dingtalkRobot.sendTextAtAll(text, opts) - send text at all
    // app.dingtalkRobot.sendLink(link, opts) - send link
    // app.dingtalkRobot.sendMarkdown(markdown, opts) - send markdown
    // app.dingtalkRobot.send(opts) - send raw
    // 创建 `自定义机器人` 即可获得
    switch (type) {
      case 'markdown':
        return await this.ctx.app.dingtalkRobot.sendMarkdown(content);
      case 'text':
        content = `监控报警:${content}`;
        return await this.ctx.app.dingtalkRobot.sendText(content);
      case 'at':
        content = `监控报警:${content}`;
        return await this.ctx.app.dingtalkRobot.sendTextAt(content);
      case 'atAll':
        content = `监控报警:${content}`;
        return await this.ctx.app.dingtalkRobot.sendTextAtAll(content);
      case 'link':
        content = `监控报警:${content}`;
        return await this.ctx.app.dingtalkRobot.sendLink(content);
      default:
        content = `监控报警:${content}`;
        return await this.ctx.app.dingtalkRobot.send(content);
    }
  }
}
module.exports = ToolService;
